package com.yjt.gcss.gddw.modules.uiSsds;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yjt.common.base.datasource.DBContextHolder;
import com.yjt.common.easyui.datagrid.DataGridDTO;
import com.yjt.common.easyui.datagrid.DataGridJsonDTO;
import com.yjt.common.tools.Jackson2JsonUtil;
import com.yjt.gcss.gddw.common.bean.domain.TxnSsds;
import com.yjt.gcss.gddw.common.bean.domain.UiSsds;
import com.yjt.gcss.gddw.modules.txnSsds.TxnSsdsService;

@Controller
@RequestMapping("/gcss/gddw/UiSsdsController")
public class UiSsdsController {

	@Resource(name = UiSsdsService.BEAN_PACKAGE_NAME)
	private UiSsdsService uiSsdsService;
	
	@Resource(name = TxnSsdsService.BEAN_PACKAGE_NAME)
	private TxnSsdsService txnSsdsService;
	
	@RequestMapping("/index")
	public String index() {
		return "/WEB-INF/admin/gcss/gddw/uiSsds/index";
	}
	
	@RequestMapping("/query")
	@ResponseBody
	public DataGridJsonDTO query(UiSsds queryModel, HttpServletRequest request) {
		DBContextHolder.setDBType(DBContextHolder.GDDW_SESSION_FACTORY);
		return uiSsdsService.query(new DataGridDTO(request), queryModel);
	}
	
	@RequestMapping("/view")
	public String view(@RequestParam(required = true)String jybsh, HttpServletRequest request) {
		DBContextHolder.setDBType(DBContextHolder.GDDW_SESSION_FACTORY);
		UiSsds uiSsds = uiSsdsService.view(jybsh);
		TxnSsds txnSsds = txnSsdsService.getTxnSsdsByReqMsgId(jybsh);
		//转化成Json对象，方便页面操作
		try {
			request.setAttribute("uiSsdsJson", Jackson2JsonUtil.beanToJson(uiSsds));
			request.setAttribute("txnSsdsJson", Jackson2JsonUtil.beanToJson(txnSsds));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/WEB-INF/admin/gcss/gddw/uiSsds/view";
	}
}
